<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <div class="contaner">我是div</div>
    <button>点击</button>
    <script>
        // 一、innerHTML:可以替换元素的超文本内容
        // 1.获取元素 2.操作元素；
        var con = document.getElementsByClassName("contaner")[0];
        var but = document.getElementsByTagName("button")[0];
        but.onclick = function() {
            var arr = [{
                name: "张三",
                age: 20,
                sex: "男",
            }, {
                name: "李四",
                age: 21,
                sex: "男",
            }, {
                name: "王五",
                age: 22,
                sex: "男",
            }, {
                name: "向浩晓",
                age: 20,
                sex: "女",
            }, ];
            var str = "<ul>";
            for (var i = 0; i < arr.length; i++) {
                str += `<li style='background:pink'>姓名${arr[i].name};年龄${arr[i].age}性别${arr[i].sex}</li>`;
            }
            str += "</ul>";
            con.innerHTML = str;
        };
    </script>
</body>

</html>